package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysApplication;
import com.ruoyi.system.service.ISysApplicationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统应用Controller
 * 
 * @author ruoyi
 * @date 2021-08-19
 */
@Controller
@RequestMapping("/system/application")
public class SysApplicationController extends BaseController
{
    private String prefix = "system/application";

    @Autowired
    private ISysApplicationService sysApplicationService;

    @RequiresPermissions("system:application:view")
    @GetMapping()
    public String application()
    {
        return prefix + "/application";
    }

    /**
     * 查询系统应用列表
     */
    @RequiresPermissions("system:application:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysApplication sysApplication)
    {
        startPage();
        List<SysApplication> list = sysApplicationService.selectSysApplicationList(sysApplication);
        return getDataTable(list);
    }

    /**
     * 导出系统应用列表
     */
    @RequiresPermissions("system:application:export")
    @Log(title = "系统应用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysApplication sysApplication)
    {
        List<SysApplication> list = sysApplicationService.selectSysApplicationList(sysApplication);
        ExcelUtil<SysApplication> util = new ExcelUtil<SysApplication>(SysApplication.class);
        return util.exportExcel(list, "系统应用数据");
    }

    /**
     * 新增系统应用
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统应用
     */
    @RequiresPermissions("system:application:add")
    @Log(title = "系统应用", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysApplication sysApplication)
    {
        return toAjax(sysApplicationService.insertSysApplication(sysApplication));
    }

    /**
     * 修改系统应用
     */
    @GetMapping("/edit/{appCode}")
    public String edit(@PathVariable("appCode") String appCode, ModelMap mmap)
    {
        SysApplication sysApplication = sysApplicationService.selectSysApplicationByAppCode(appCode);
        mmap.put("sysApplication", sysApplication);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统应用
     */
    @RequiresPermissions("system:application:edit")
    @Log(title = "系统应用", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysApplication sysApplication)
    {
        return toAjax(sysApplicationService.updateSysApplication(sysApplication));
    }

    /**
     * 删除系统应用
     */
    @RequiresPermissions("system:application:remove")
    @Log(title = "系统应用", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysApplicationService.deleteSysApplicationByAppCodes(ids));
    }
}
